package com.gzyj.jtt808.v2013.protocol.subiao;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2011.protocol.subiao.AlarmIdentificationProperty;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.nio.charset.Charset;

@Data
public class JTT808_0x9208 extends Package implements Serializable {


    @ApiModelProperty("服务IP地址")
    public String AttachmentServerIP ;

    @ApiModelProperty("TCP端口")
    public Integer AttachmentServerIPTcpPort ;

    @ApiModelProperty("UDP端口")
    public Integer AttachmentServerIPUdpPort ;

    @ApiModelProperty("报警标识号")
    public AlarmIdentificationProperty AlarmIdentification ;

    @ApiModelProperty("平台给报警分配的唯一编号")
    public String AlarmId ;

    @ApiModelProperty("预留")
    public byte[] Retain  = new byte[16];


    public JTT808_0x9208(){
        super(BusinessDataType.报警附件上传指令.getCode());
    }


    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeByte(this.AttachmentServerIP.getBytes(Charset.forName("GBK")).length);
        buf.writeCharSequence(this.AttachmentServerIP,Charset.forName("GBK"));
        buf.writeShort(this.AttachmentServerIPTcpPort);
        buf.writeShort(this.AttachmentServerIPUdpPort);
        this.AlarmIdentification.encode(buf);

        buf.writeBytes(HexBytesUtil.WriteStringPadRight(this.AlarmId,32));
        buf.writeBytes(this.Retain);


    }

    @Override
    public JTT808_0x9208 decodeImpl(ByteBuf buf) {
        int len=buf.readByte();
        this.AttachmentServerIP=new String(HexBytesUtil.readByOffset(buf,len),Charset.forName("GBK")).trim();
        this.AttachmentServerIPTcpPort=buf.readUnsignedShort();
        this.AttachmentServerIPUdpPort=buf.readUnsignedShort();
        this.AlarmIdentification=new AlarmIdentificationProperty();
        this.AlarmIdentification.decode(buf);
        this.AlarmId=new String(HexBytesUtil.readByOffset(buf,32)).trim();
        this.Retain=HexBytesUtil.readByOffset(buf,16);

        return this;
    }

}
